public class Test {
    public ListNode Merge (ListNode pHead1, ListNode pHead2) {
        // write code here
        if(pHead1 == null && pHead2 == null) {
            return null;
        }

        ListNode node = new ListNode(1);
        ListNode curA = pHead1;
        ListNode curB = pHead2;

        ListNode cur = node;

        while(curA != null && curB != null) {
            if(curA.val < curB.val) {
                cur.next = curA;
                cur = curA;
                curA = curA.next;
            } else {
                cur.next = curB;
                cur = curB;
                curB = curB.next;
            }

        }
        if(curA == null) {
            cur.next = curB;
        }
        if(curB == null) {
            cur.next = curA;
        }
        return node.next;

    }
    public ListNode Merge (ListNode pHead1, ListNode pHead2) {
        // write code here
        if(pHead1 == null && pHead2 == null) {
            return null;
        }

        ListNode node = new ListNode(1);
        ListNode curA = pHead1;
        ListNode curB = pHead2;

        ListNode cur = node;

        while(curA != null && curB != null) {
            if(curA.val < curB.val) {
                cur.next = curA;
                cur = curA;
                curA = curA.next;
            } else {
                cur.next = curB;
                cur = curB;
                curB = curB.next;
            }

        }
        if(curA == null) {
            cur.next = curB;
        }
        if(curB == null) {
            cur.next = curA;
        }
        return node.next;

    }
}
